package com.wrater.zero.common.base;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class BaseException extends RuntimeException {

    /**
     * 状态码
     */
    private final Integer code;

    /**
     * 异常地址
     */
    private final String address;

    /**
     * 自定义异常
     *
     * @param resultEnum  异常枚举对象
     * @param address     异常地址
     */
    public BaseException(ResultExceptionEnum resultEnum, String address) {
        super(resultEnum.getMsg());
        this.code = resultEnum.getCode();
        this.address = address;
    }

    /**
     * @param code    状态码
     * @param message 错误信息
     * @param address 异常地址
     */
    public BaseException(Integer code, String message, String address) {
        super(message);
        this.code = code;
        this.address = address;
    }

    /**
     *  抛出业务异常
     * @param code    状态码
     * @param message 错误信息
     * @param address 异常地址
     */
    public static void throwException(Integer code,String message, String address){
        throw new BaseException(code, message, address);
    }

    /**
     * 抛出业务异常
     * @param resultEnum    异常枚举对象
     * @param address       异常地址
     */
    public static void throwException(ResultExceptionEnum resultEnum, String address){
        throw new BaseException(resultEnum, address);
    }

    /**
     * 抛出业务异常
     * @param address   异常地址
     */
    public static void throwException(String address){
        throw new BaseException(ResultExceptionEnum.DEFAULT_EXCEPTION, address);
    }

    /**
     * 抛出业务异常
     * @param cls   异常抛出类
     */
    public static void throwException(Class cls){
        throw new BaseException(ResultExceptionEnum.DEFAULT_EXCEPTION, cls.getName());
    }

    /**
     * 抛出业务异常
     * @param message   错误信息
     * @param address   异常地址
     */
    public static void throwException(String message, String address){
        throw new BaseException(ResultExceptionEnum.DEFAULT_EXCEPTION.getCode(), message, address);
    }

    /**
     * 抛出业务异常
     * @param message   错误信息
     * @param cls       异常抛出类
     */
    public static void throwException(String message, Class cls){
        throw new BaseException(ResultExceptionEnum.DEFAULT_EXCEPTION.getCode(), message, cls.getName());
    }

    /**
     *
     * @param resultEnum    异常枚举对象
     * @param cls           异常抛出类
     */
    public static void throwException(ResultExceptionEnum resultEnum, Class cls){
        throw new BaseException(resultEnum, cls.getName());
    }


}